package com.ruoyi.approve.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.approve.domain.approveYsZhu;
import com.ruoyi.approve.service.approveYsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审批预算Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/approveys/approveys")
public class approveYsController extends BaseController
{
    @Autowired
    private approveYsService assetGzyusuanZhuService;

    /**
     * 查询审批预算列表
     */
    @PreAuthorize("@ss.hasPermi('approveys:approveys:list')")
    @GetMapping("/list")
    public TableDataInfo list(approveYsZhu assetGzyusuanZhu)
    {
        startPage();
        List<approveYsZhu> list = assetGzyusuanZhuService.selectAssetGzyusuanZhuList(assetGzyusuanZhu);
        return getDataTable(list);
    }

    /**
     * 导出审批预算列表
     */
    @PreAuthorize("@ss.hasPermi('approveys:approveys:export')")
    @Log(title = "审批预算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, approveYsZhu assetGzyusuanZhu)
    {
        List<approveYsZhu> list = assetGzyusuanZhuService.selectAssetGzyusuanZhuList(assetGzyusuanZhu);
        ExcelUtil<approveYsZhu> util = new ExcelUtil<approveYsZhu>(approveYsZhu.class);
        util.exportExcel(response, list, "审批预算数据");
    }

    /**
     * 获取审批预算详细信息
     */
    @PreAuthorize("@ss.hasPermi('approveys:approveys:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetGzyusuanZhuService.selectAssetGzyusuanZhuById(id));
    }

    /**
     * 打回审批预算
     */
    @PreAuthorize("@ss.hasPermi('approveys:approveys:remove')")
    @Log(title = "打回审批预算", businessType = BusinessType.DELETE)
    @DeleteMapping("/{nid}")
    public AjaxResult handleNo(@PathVariable("nid") Long[] nid)
    {
        System.out.println("审批失败");
        return toAjax(assetGzyusuanZhuService.handleNo(nid));
    }
    /**
     * 打回审批预算
     */
    @PreAuthorize("@ss.hasPermi('approveys:approveys:put')")
    @Log(title = "打回审批预算", businessType = BusinessType.UPDATE)
    @PutMapping("/{yid}")
    public AjaxResult handleYes(@PathVariable("yid") Long[] yid)
    {
        System.out.println("审批成功");
        return toAjax(assetGzyusuanZhuService.handleYes(yid));
    }
}
